import repository from '../../net/repository'

// initial state
// shape: [{ id, quantity }]
const state = {
    //当前趋势列表
    trend_repos_data_list: [],
    trend_repos_current_size: 0,
};

// getters
const getters = {};

// actions
const actions = {
  getContent({commit, state}, params) {
        let page = params.page
        repository.getContent(page).then((res) => {

            if (res && res.data) {
                res.data.forEach((item) => {
                    let ex = {
                        title: item.contents.title,
                        image: item.thumbnail_path,
                        tag: item.contents.tags[0],
                        view_count: item.contents.view_count
                    }
                    item.ex = ex
                });
              if (page <= 1) {
                commit('storeContent', res.data);
              }else{
                commit('addContent', res.data);
              }
            }
            params.callback && params.callback(res);
        });

    },
};

// mutations
const mutations = {
    storeContent(state, list) {
        state.trend_repos_data_list = list;
    },
    addContent(state, list) {
      state.trend_repos_data_list = state.trend_repos_data_list.concat(
        list)
    }
};

export default {
    state,
    getters,
    actions,
    mutations
}
